<template>
  <div class="app-container">
    <el-form>
      <el-form-item
        label="启动优惠劵"
        label-width="88px"
      >
        <el-switch
          v-model="couponEnabledFlag"
          active-value="1"
          inactive-value="0"
          @change="handleFlagChange()"
        ></el-switch>
      </el-form-item>
      <hr />
    </el-form>
    <div v-if="couponEnabledFlag == 1">
      <el-form
        :model="queryForm"
        ref="queryForm"
        :inline="true"
        label-width="88px"
        class="globalSerchFormStyle"
      >
        <el-row>
          <el-col :span="5.5">
            <el-form-item
              label="优惠券标识"
              prop="couponRemark"
            >
              <el-input
                v-model="queryForm.couponRemark"
                placeholder="请输入标识"
                clearable
                size="small"
                style="width: 170px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5.5">
            <el-form-item
              label="优惠券类型"
              prop="couponType"
            >
              <el-select
                v-model="queryForm.couponType"
                clearable
                size="small"
                placeholder="请选择"
                style="width: 170px"
              >
                <el-option
                  label="现金券"
                  value="1"
                ></el-option>
                <el-option
                  label="折扣券"
                  value="2"
                ></el-option>
                <el-option
                  label="兑换券"
                  value="3"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5.5">
            <el-form-item
              label="优惠券名称"
              prop="couponName"
            >
              <el-input
                v-model="queryForm.couponName"
                placeholder="请输入名称"
                clearable
                size="small"
                style="width: 170px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5.5">
            <el-form-item
              label="生效状态"
              prop="status"
            >
              <el-select
                v-model="queryForm.status"
                clearable
                placeholder="请选择"
                size="small"
                style="width: 170px"
              >
                <el-option
                  label="开启"
                  value="1"
                ></el-option>
                <el-option
                  label="关闭"
                  value="0"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-show="collapse">
          <el-col>
            <el-form-item
              label="创建时间"
              prop="getCreateTime"
            >
              <el-date-picker
                style="width: 330px"
                v-model="dateRangeCreatedDate"
                size="small"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div style="margin-bottom: 14px;">

        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
        <el-button
          type="danger"
          :disabled="selectionChangeList.length < 1"
          icon="el-icon-delete"
          size="mini"
          @click="handleDelete"
        >删除</el-button>
        <!-- <el-button disable size="mini">导出兑换码</el-button> -->
      </div>
      <el-table
        :data="couponList"
        height="400"
        @selection-change="selectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
        />
        <!-- <af-table-column label="优惠券标识" align="left" prop="couponRemark" fixed="left" /> -->
        <af-table-column
          label="油站名称"
          prop="stationName"
        />
        <af-table-column
          label="优惠券名称"
          prop="issueRemark"
        />
        <af-table-column
          label="优惠券ID"
          prop="couponId"
        />
        <af-table-column
          label="优惠券类型"
          prop="couponType"
          :formatter="formatterCouponType"
        />
        <af-table-column
          label="生效状态"
          prop="status"
          :formatter="formatterStatus"
        />
        <af-table-column
          label="优惠券有效期"
          align="left"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.startDate }} - {{ scope.row.endDate }}</span>
          </template>
        </af-table-column>
        <af-table-column
          label="创建时间"
          prop="createTime"
        />
        <af-table-column
          label="优惠说明"
          prop="couponDetails"
        />
        <af-table-column
          label="核销机构"
          prop="stationName"
        >
          <!-- <template slot-scope="scope">
            {{
              scope.row.couponType == 1 || scope.row.couponType == 2
                ? "------------"
                : ""
            }}
            {{ scope.row.couponType == 3 ? ((!scope.row.verificationList || scope.row.verificationList.length == 0) ?
              "仅自家站点" : (scope.row.verificationNameList || []).toString()) : '' }}
          </template> -->
        </af-table-column>

        <af-table-column
          label="操作"
          align="left"
          class-name="small-padding fixed-width"
          width="120px"
        >
          <template slot-scope="scope">
            {{ scope.row.editFlag == "1" ? "" : "" }}
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-if="scope.row.editFlag == '0'"
            >修改</el-button>
          </template>
        </af-table-column>
      </el-table>
      <pagination
        :hidden="total > 0 ? false : true"
        :total="total"
        :page.sync="queryForm.pageNum"
        :limit.sync="queryForm.pageSize"
        @pagination="getCoupon"
        :autoScroll="true"
      />
    </div>
    <div
      v-else
      style="text-align: center"
    >
      亲，您的油站暂未启动优惠券功能，呦~
    </div>

    <!-- 添加或修改油站设备管理对话框 -->

    <el-dialog
      :title="title"
      :visible.sync="open"
      width="600px"
      append-to-body
      status-icon
    >
      <el-form
        ref="createForm"
        :model="createForm"
        :rules="rules"
        label-width="180px"
      >
        <el-form-item
          label="优惠劵标识(给油站备注)"
          prop="couponRemark"
          :rules="{
          required: true,
          message: '标签不能为空，不需要请删除此项',
          trigger: 'blur',
        }"
        >
          <input
            type="text"
            class="form-control"
            v-model="createForm.couponRemark"
            style="width: 180px"
          />
        </el-form-item>
        <el-form-item
          label="优惠券类型"
          prop="couponType"
          :rules="{
          required: true,
          message: '请选择优惠券类型',
          trigger: 'change',
        }"
        >
          <el-radio-group v-model="createForm.couponType">
            <el-radio label="1">现金券</el-radio>
            <el-radio label="2">折扣劵</el-radio>
            <el-radio label="3">兑换劵</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="优惠劵名称(给用户展示)"
          prop="couponName"
          v-if="createForm.couponType == 3"
          :rules="{
          required: createForm.couponType == 3,
          message: '请填写优惠券名称',
          trigger: 'blur',
        }"
        >
          <input
            type="text"
            class="form-control"
            v-model="createForm.couponName"
            style="width: 180px"
          />
        </el-form-item>
        <el-form-item
          label="优惠劵说明(给用户展示)"
          prop="couponDetails"
          :rules="{
          required: true,
          message: '请填写优惠券说明',
          trigger: 'blur',
        }"
        >
          <input
            type="text"
            class="form-control"
            v-model="createForm.couponDetails"
            style="width: 180px"
          />
        </el-form-item>

        <el-form-item
          label="优惠金额"
          prop="couponAmt"
          v-if="createForm.couponType == 1 || createForm.couponType == 2"
          :rules="{
            required: createForm.couponType == 1 || createForm.couponType == 2,
            message: '请填写优惠券适用条件',
            trigger: 'blur',
          }"
        >
          <div v-if="createForm.couponType == 1">
            固定面值—<input
              type="text"
              class="form-control d-inline"
              v-model.number="createForm.couponAmt"
              style="width: 100px"
            />
            元
          </div>
          <div v-if="createForm.couponType == 2">
            折扣比例—<input
              type="text"
              class="form-control d-inline"
              v-model.number="createForm.couponAmt"
              style="width: 100px"
            />
            %
          </div>
        </el-form-item>
        <!--
        <el-form-item
          label="优惠券适用油品"
          prop="oilIdLists"
          v-if="createForm.couponType == 1 || createForm.couponType == 2"
        >
          <el-checkbox-group v-model="createForm.oilIdLists">
            <el-checkbox
              :label="item.oilId"
              v-for="(item) in currentOilList"
              :key="item.oilId"
            >{{
                  item.oilName + " - " + item.oilType + " - " + item.oilClass
                }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        -->
        <el-form-item
          label="优惠券有效期"
          prop="effectiveTimeType"
        >
          <div>
            <div>
              <el-radio-group v-model="createForm.effectiveTimeType">
                <el-radio label="1">固定时间段</el-radio>
                <el-radio label="2">固定天数</el-radio>
              </el-radio-group>
            </div>
            <div style="margin-top: 10px">
              <div v-if="createForm.effectiveTimeType == 1">
                <el-date-picker
                  style="margin: 0px 10px; width: 300px"
                  v-model="createForm.effectiveTime"
                  type="datetimerange"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  size="mini"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                >
                </el-date-picker>
              </div>
              <div
                v-if="createForm.effectiveTimeType == 2"
                style="margin-left: 20px"
              >
                自用户领取后
                <input
                  type="text"
                  class="form-control d-inline"
                  v-model.number="createForm.effectiveDayNum"
                  style="width: 80px"
                />
                天内有效
              </div>
            </div>
          </div>
        </el-form-item>

        <el-form-item
          label="生成优惠券的数量"
          prop="couponNum"
          :rules="{
          required: true,
          message: '请填写生成数量',
          trigger: 'blur',
        }"
        >
          共生成
          <input
            type="text"
            class="form-control d-inline"
            v-model.number="createForm.couponNum"
            style="width: 100px"
          />
          张
        </el-form-item>

        <el-form-item
          label="优惠券的核销方"
          prop="verificationList"
          v-if="createForm.couponType == 3"
        >
          （自己的站点是默认必选的核销商）
        </el-form-item>
        <div v-if="createForm.couponType == 3">
          <el-col :span="11">
            <el-table
              :data="unselectedCouponList"
              border
              size="mini"
              :resizable="false"
              highlight-current-row
              height="500"
              @selection-change="handleLeftChange"
              disabled
              ref="leftTable"
            >
              >
              <el-table-column label="可选">
                <el-table-column
                  prop="phone"
                  label="机构"
                  type="selection"
                ></el-table-column>
                <el-table-column
                  prop="stationName"
                  label="机构"
                ></el-table-column>
                <el-table-column
                  label="添加"
                  width="60px"
                  align="left"
                >
                  <template slot-scope="scope">
                    <el-button
                      type="text"
                      icon="el-icon-circle-plus-outline"
                      class="underline btn24"
                      size="mini"
                      @click="handleMoveLabel('right', scope.row)"
                    >添加</el-button>
                  </template>
                </el-table-column>
              </el-table-column>
            </el-table>
          </el-col>
          <el-col
            :span="2"
            style="text-align: center"
          >
            <el-button
              type="primary"
              size="mini"
              @click="toggleLabel"
              style="
                margin-top: 200px;
                text-align: center;
                width: 30px;
                padding-right: 0;
                padding-left: 0;
              "
              :disabled="toggleable"
            >切换</el-button>
          </el-col>
          <el-col :span="11">
            <el-table
              :data="selectedCouponList"
              border
              size="mini"
              highlight-current-row
              :resizable="false"
              height="500"
              @selection-change="handleRightChange"
              :loading="true"
              ref="rightTable"
            >
              <el-table-column
                label="已选"
                :resizable="false"
              >
                <el-table-column
                  prop="phone"
                  type="selection"
                ></el-table-column>
                <el-table-column
                  prop="stationName"
                  label="姓名"
                ></el-table-column>
                <el-table-column
                  label="移除"
                  width="60px"
                  align="left"
                >
                  <template slot-scope="scope">
                    <el-button
                      type="text"
                      icon="el-icon-remove-outline"
                      class="underline btn24"
                      size="mini"
                      @click="handleMoveLabel('left', scope.row)"
                    >移除</el-button>
                  </template>
                </el-table-column>
              </el-table-column>
            </el-table>
          </el-col>
        </div>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          type="primary"
          @click="submitForm"
        >确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPrice } from "@/api/station/price";
import SelectDay from "@/components/SelectDay";

import {
  addInfo,
  verificationList,
  listInfo,
  updateInfo,
  changeCouponStatus,
  selectCouponEnableFalge,
} from "@/api/coupon";

import { creationList, creationDelete } from "@/api/coupon/creation";
import { getOilList } from "@/api/dept";
export default {
  name: "Coupon_CreateCoupon",
  data() {
    let validateOilNameList = (rule, value, callback) => {
      if (value.length == 0) {
        callback(new Error("请选择优惠券的使用油品"));
        return;
      }
      callback();
    };
    let validateEffectiveTimeType = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请填入有效时间"));
        return;
      }
      if (value == 1) {
        if (this.createForm.effectiveTime.length == 0) {
          callback(new Error("请选择有效时间"));
          return;
        }
      }
      if (value == 2) {
        if (!this.createForm.effectiveDayNum) {
          callback(new Error("请填入有效天数"));
          return;
        }
      }
      callback();
    };
    return {
      //创建优惠券的时间
      dateRangeCreatedDate: [],
      couponEnabledFlag: "1",
      // 油站设备管理表格数据
      createForm: {
        couponRemark: "",
        couponName: "",
        couponDetails: "",
        couponType: "1",
        couponAmt: "",
        oilIdLists: [],
        effectiveTimeType: "", //有效时间类型： 1，固定时间；2，领取后x天内有效
        effectiveTime: [],
        effectiveDayNum: 30,
        couponNum: 100,
        status: "1",
      },
      couponList: [],
      allVerificationList: [],
      day: [],
      cycle: [],

      deviceTypeOptions: [],
      stationOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 总条数
      total: 100,
      leftQuery: {},
      rightQuery: {},
      leftData: [],
      rightData: [],
      moveRightData: [],
      moveLeftData: [],
      // 查询参数
      queryForm: {
        pageNum: 1,
        pageSize: 10, // 初始值只能比10大
        couponName: null,
        couponRemark: null,
        couponType: null,
        levelId: this.levelId,
        couponRemark: null,
        status: null,
        getCreateTime: null,
      },
      // 表单校验
      rules: {
        oilIdLists: [
          { required: true, message: "请选择适用油品", trigger: "change" },
          { validator: validateOilNameList, trigger: "change" },
        ],
        effectiveTimeType: [
          { required: true, message: "请输入有效期类型", trigger: "change" },
          { validator: validateEffectiveTimeType, trigger: "change" },
        ],
      },
      timeSelect: [
        ,
        ["周天", "周一", "周二", "周三", "周四", "周五", "周六"],
        [
          "1号",
          "2号",
          "3号",
          "4号",
          "5号",
          "6号",
          "7号",
          "8号",
          "9号",
          "10号",
          "11号",
          "12号",
          "13号",
          "14号",
          "15号",
          "16号",
          "17号",
          "18号",
          "19号",
          "20号",
          "21号",
          "22号",
          "23号",
          "24号",
          "25号",
          "26号",
          "27号",
          "28号",
          "29号",
          "30号",
          "31号",
        ],
      ],
      currentOilList: [],
      collapse: false,
      selectionChangeList: [],
    };
  },
  created() {
    this.init();
    this.getOilList();
    console.log("-----------");
  },
  computed: {
    toggleable() {
      if (this.moveRightData.length === 0 && this.moveLeftData.length === 0) {
        return true;
      }
      return false;
    },
    selectedCouponList() {
      return this.allVerificationList.filter((ele) => {
        if (this.createForm.verificationList == null) {
          this.createForm.verificationList = [];
        }
        return this.createForm.verificationList.includes(ele.stationId);
      });
    },
    unselectedCouponList() {
      return this.allVerificationList.filter((ele) => {
        if (this.createForm.verificationList == null) {
          this.createForm.verificationList = [];
        }
        return !!!this.createForm.verificationList.includes(ele.stationId);
      });
    },
  },
  components: {
    SelectDay: SelectDay,
  },
  methods: {
    selectionChange(selection) {
      this.selectionChangeList = selection;
    },
    // 查询油企
    getEnterpriseList() {
      enterpriseList().then((res) => {
        this.enterpriseList = res.rows;
      });
    },
    // 查询油站
    getStationList(val, key) {
      listEnterpriseStation({ enterpriseId: val }).then((res) => {
        if (key === "search") {
          this.stationList = res;
        } else {
          this.stationListForm = res;
        }
      });
    },
    // 搜索选择油企
    handleSelectChange(val) {
      this.stationList = [];
      this.queryForm.stationId = null;
      this.getStationList(val, "search");
    },
    handleSelectChangeAddOrEdit(val) {
      this.stationListForm = [];
      this.createForm.stationId = null;
      this.getStationList(val);
    },

    /** 查询优惠券模板信息*/
    getList() {
      listInfo(this.addDateRange(this.queryForm, this.dateRangeCreatedDate))
        .then((res) => {
          if (res.code == 200) {
            if (res.rows == null) {
              this.total = 0;
              this.couponList = [];
            } else {
              this.total = res.total;
              this.couponList = res.rows;
            }
          } else {
            throw new Error("");
          }
        })
        .catch((err) => {
          this.msgError("亲，拉取优惠券列表失败~");
        });
    },

    getTodayDateString() {
      const date = new Date();
      let y = date.getFullYear();
      let m = date.getMonth().toString();
      let s = date.getDate().toString();
      m = "" + (m.length == 1 ? "0" : "") + m;
      s = "" + (s.length == 1 ? "0" : "") + s;
      return "" + y + ":" + m + ":" + s;
    },
    handleMoveLabel(direction, row) {
      if (!this.createForm.verificationList) {
        this.createForm.verificationList = [];
      }
      console.log("22");
      if (direction == "right") {
        this.createForm.verificationList.push(row.stationId);
      } else {
        this.createForm.verificationList =
          this.createForm.verificationList.filter((ele) => {
            return ele != row.stationId;
          });
      }
      this.createForm = { ...this.createForm };
    },
    handleFlagChange() {
      const that = this;
      let text = this.couponEnabledFlag === "1" ? "启用" : "停用";
      this.$confirm('确认要"' + text + '"优惠券功能吗?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return changeCouponStatus(that.couponEnabledFlag);
        })
        .then(() => {
          that.msgSuccess(text + "成功");
        })
        .catch(function () {
          that.couponEnabledFlag = that.couponEnabledFlag === "0" ? "1" : "0";
        });
    },
    getVerificationList() {
      verificationList({
        pageNum: 1,
        pageSize: 1000,
      })
        .then((res) => {
          if (res.code == 200) {
            if (res.rows == null) {
              this.allVerificationList = [];
            } else {
              this.allVerificationList = res.rows;
            }
          } else {
            throw new Error("");
          }
        })
        .catch((err) => {
          this.msgError("亲，拉取核销机构失败~");
        });
    },
    toggleLabel() {
      if (this.moveLeftData.length !== 0) {
        this.createForm.verificationList =
          this.createForm.verificationList.filter((ele) => {
            return ele != this.moveLeftData;
          });
        this.createForm = { ...this.createForm };
        return;
      }
      if (this.moveRightData.length !== 0) {
        this.createForm.verificationList = [
          ...new Set(
            this.createForm.verificationList.concat(this.moveRightData)
          ),
        ].filter((ele) => {
          return !!ele;
        });
        this.createForm = { ...this.createForm };
        return;
      }
      return;
    },
    handleLeftChange(val) {
      let changeArr = [];
      val.map((ele) => {
        changeArr.push(ele.stationId);
      });
      this.moveLeftData = [];
      this.moveRightData = changeArr;
      this.$refs.rightTable.clearSelection();
    },
    handleRightChange(val) {
      let changeArr = [];
      val.map((ele) => {
        changeArr.push(ele.stationId);
      });
      this.moveLeftData = changeArr;
      this.moveRightData = [];
      this.$refs.leftTable.clearSelection();
    },
    init() {
      selectCouponEnableFalge()
        .then((res) => {
          if (res.code == 200) {
            this.couponEnabledFlag = res.data.toString();
            this.getOilList();
            this.getCoupon();
            this.getVerificationList();
          } else {
            throw new Error("");
          }
        })
        .catch((err) => {
          this.msgError("拉取优惠券配置失败");
        });
    },
    getCoupon() {
      listInfo(this.queryForm)
        .then((res) => {
          if (res.code == 200) {
            if (res.rows == null) {
              this.total = 0;
              this.couponList = [];
            } else {
              this.total = res.total;
              this.couponList = res.rows;
            }
          } else {
            throw new Error("");
          }
        })
        .catch((err) => {
          this.msgError("亲，拉取优惠券列表失败~");
        });
    },
    getOilList() {
      getOilList({
        pageSize: 1000,
        pageNum: 1,
      }).then((res) => {
        if (res.rows == null) {
          this.currentOilList = [];
          return;
        }
        this.currentOilList = res.rows;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.createForm.pageNum = 1;
      this.getList();
    },
    deviceNoInput(value) {
      this.createForm.posQueue = value;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryForm.pageNum = 1;
      this.queryForm.pageSize = 10;
      this.dateRangeCreatedDate = [];
      //this.queryForm.couponRemark=null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.title = "添加优惠券";
      this.createForm = {
        couponRemark: "",
        couponName: "",
        couponDetails: "",
        couponType: "1",
        couponAmt: "",
        oilIdLists: [],
        effectiveTimeType: "", //有效时间类型： 1，固定时间；2，领取后x天内有效
        effectiveTime: [],
        effectiveDayNum: 30,
        couponNum: 100,
        status: "1",
      };
      this.open = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // // 查找自己已经选中的枪号
      const createForm = JSON.parse(JSON.stringify(row));
      this.createForm = createForm;
      this.title = "修改油站设备管理";
      this.open = true;
    },
    // 获取n天后的日期
    getTargetDate(startDate, days) {
      var startTime = new Date(startDate).getTime();
      var diff = days * 86400 * 1000;
      var endTime = startTime + diff;
      var d = new Date(endTime);
      var CurrentDate = "";
      CurrentDate += d.getFullYear();
      //var year=(d.getFullYear())+"-"+(d.getMonth()+1)+"-"+(d.getDate());
      if (d.getMonth() + 1 > 9) {
        CurrentDate += "-" + (d.getMonth() + 1);
      } else {
        CurrentDate += "-0" + (d.getMonth() + 1);
      }
      if (d.getDate() > 9) {
        CurrentDate += "-" + d.getDate();
      } else {
        CurrentDate += "-0" + d.getDate();
      }
      return CurrentDate;
    },
    getCurrentDate() {
      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      month = month > 9 ? month : "0" + month;
      day = day < 10 ? "0" + day : day;
      return year + "-" + month + "-" + day;
    },
    formatterStatus(row, column) {
      const types = {
        0: "待生效",
        1: "生效中",
        2: "生效已暂停",
        3: "已失效",
      };
      return types[row.status] ?? "";
    },
    formatterCouponType(row, column) {
      const types = {
        1: "现金劵",
        2: "折扣劵",
        3: "兑换券",
      };
      return types[row.couponType] ?? "";
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["createForm"].validate((valid) => {
        if (valid) {
          if (!!this.createForm.id) {
            updateInfo(this.createForm)
              .then((res) => {
                if (res.code == 200) {
                  this.msgSuccess("亲，修改成功了~");
                  this.getCoupon();
                  this.open = false;
                } else {
                  throw new Error("");
                }
              })
              .catch((err) => {
                this.msgError("修改失败了呀~");
              });
          } else {
            let effectiveTimeStart = this.getCurrentDate();
            this.createForm.effectiveTime.push(
              effectiveTimeStart + " 00:00:00"
            );
            let effectiveTimeEnd = this.getTargetDate(
              effectiveTimeStart,
              this.createForm.effectiveDayNum
            );
            this.createForm.effectiveTime.push(effectiveTimeEnd + " 00:00:00");
            addInfo(this.createForm)
              .then((res) => {
                if (res.code == 200) {
                  this.msgSuccess("亲，新增成功了~");
                  this.getCoupon();
                  this.open = false;
                } else {
                  throw new Error("");
                }
              })
              .catch((err) => {
                this.msgError("创建优惠劵失败了~");
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete() {
      this.$confirm(`确认删除勾选的优惠卷吗？`).then(() => {
        let ids = this.selectionChangeList.map((item) => item.id);
        creationDelete(ids).then((res) => {
          if (res && res.code === 200) {
            this.$message.success(res.msg);
            this.selectionList = [];
            this.getList();
          } else {
            this.$message.error(res.msg);
          }
        });
      });
    },
  },
};
</script>
<style lang="scss">
// .el-transfer__buttons {
// }
</style>
